const path = require('path');

const Koa = require('koa');

const errHandle = require('./error.handle');

const app = new Koa();

const koaBody = require('koa-body');
const koaStatic = require('koa-static');

app.use(koaBody({
    // 文件上传
    multipart: true,
    formidable: {
        uploadDir: path.join(__dirname, '../upload'),
        keepExtensions: true
    }
}));
// 设置静态文件路径
app.use(koaStatic(path.join(__dirname, '../upload')));

// 路由 ../router/index.js  index可省略
const router = require('../router');

app.use(router.routes());
// 限制http请求类型
app.use(router.allowedMethods());


// 统一的错误处理
app.on('error', errHandle);

module.exports = app;